package basicservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type FinanceAccountSubjectEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFinanceAccountSubjectEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FinanceAccountSubjectEditLogic {
	return &FinanceAccountSubjectEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// FinanceAccountSubjectEdit 更新财务科目表项
func (l *FinanceAccountSubjectEditLogic) FinanceAccountSubjectEdit(in *property_service.FinanceAccountSubject) (*property_service.Response, error) {
	// 获取财务科目表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).FinanceAccountSubject
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、CreatedAt、UpdatedAt
	if _, err := do.UpdateColumns(&model.FinanceAccountSubject{
		ParentID:         in.ParentID,         // 父级ID
		ParentCode:       in.ParentCode,       //父级编码
		ParentLs:         in.ParentLs,         // 父级列表
		SubjectCode:      in.SubjectCode,      // 科目编码
		SubjectName:      in.SubjectName,      // 科目名称
		BalanceDirection: in.BalanceDirection, // 余额方向
		SubjectID:        in.SubjectID,        // 科目类型id
		SubjectType:      in.SubjectType,      // 科目类型
		UpdatedAtuser:    in.UpdatedAtuser,    // 更新人
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
